<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
class ShopattController extends AdminController {
    public function index(){
        $nickname       =   I('nickname');
        $map['status']  =   array('egt',0);
        if(is_numeric($nickname)){
            $map['uid|nickname']=   array(intval($nickname),array('like','%'.$nickname.'%'),'_multi'=>true);
        }else{
            $map['nickname']    =   array('like', '%'.(string)$nickname.'%');
        }
        $list = $this->lists('Shopatt',$map);
        $list = M()->table('onethink_shop b,onethink_shopatt a')->where("b.id=a.pid")->select();
        $this->assign('_list', $list);
        $this->meta_title = '商品属性';
        $this->display();
    }
    public function delete(){
            $id=I('get.id');
            $att=M('att');
            $re=$att->where('pid='.$id)->find();
            $res=M('shopatt')->where("id=$id")->delete($_POST);
            if ($res) {
                if($re){
                     $res=$att->where("pid=$id")->delete();
                     $this->success('删除成功',U('index'));
                }else{
                    $this->success('删除成功',U('index'));
                }
            }else{
                $this->error('删除失败',U('index'));
    }
    }
    public function update(){
        if (IS_POST) {
            $id=I('post.id'); 
            $res=M('shopatt')->where("id=$id")->save($_POST);
            if ($res) {
                $this->success('修改成功',U('index'));
            }else{
                $this->error('修改失败',U('index'));
            }
        }else{
             $id=I('get.id');
             $User = M("shopatt")->find("$id");// 实例化User对象
             $this->assign('User',$User);
             $this->display();
        }
   }
     public function setStatus($model='Shopatt'){
        return parent::setStatus($model);
    }

    public function changeStatus($method=null){
        $id = array_unique((array)I('id',0));
        $id = is_array($id) ? implode(',',$id) : $id;
        if ( empty($id) ) {
            $this->error('请选择要操作的数据!');
        }
        $map['id'] =   array('in',$id);
        switch ( strtolower($method) ){
            case 'forbiduser':
                $this->forbid('shopatt', $map );
                break;
            case 'resumeuser':
                $this->resume('shopatt', $map );
                break;
            case 'deleteuser':
                $this->delete('shopatt', $map );
                break;
            default:
                $this->error('参数非法');
        }
    }
    
  }